<?php

namespace App\Http\Requests\Entity\Column;

use App\Http\Requests\Request;

class CollistRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'GET':
            case 'DELETE':
                {
                    return [];
                }
            // Crate
            case 'POST':
                {
                    return [
                        // 'collist_no' => 'required|max:100|unique:collists,collist_no',
                        'name'         => 'required|max:100',
                        'title'        => 'required|max:100',
                        'subtitle'     => 'max:100',
                        'short_desc'   => 'max:100',
                        // 'img'        => 'max:200',
                        'listorder'    => 'required',
                        'term_type_id' => 'required',
                        'level'        => 'required',
                    ];
                }
            // UPDATE
            case 'PUT':
            case 'PATCH':
                {
                    $id = $this->route('collists');
                    return [
                        // 'collist_no' => 'required|max:100|unique:collists,collist_no,' . $id,
                        'name'       => 'required|max:100',
                        'title'      => 'required|max:100',
                        'subtitle'   => 'max:100',
                        'short_desc' => 'max:100',
                        // 'img'        => 'max:200',
                        'listorder'  => 'required',
                    ];
                }
            default:
                break;
        }
    }
    public function messages()
    {
        return [
            'name.required'         => '名称 不能为空',
            'name.max'              => '名称 不能大于100个字符',
            'short_desc.max'        => '简介 不能大于100个字符',
            'title.max'             => '标题 不能大于100个字符',
            'title.required'        => '标题 不能为空',
            'subtitle.max'          => '副标题 不能大于100个字符',
            'listorder.required'    => '排序 不能为空',
            'term_type_id.required' => '设备类型 不能为空',
        ];
    }
}
